package com.example.administrator.appli;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.appli.service.LocalServiceCount;

public class LocalServiceActivity extends Activity {
    private static final String TAG = "LocalServiceActivity";
    LocalServiceCount.MyBinder myBinder;
    ServiceConnection connection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {

            myBinder = (LocalServiceCount.MyBinder) service;
            Log.e(TAG, "onCreate: " + myBinder.add(111, 22));
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };
    TextView tv_add;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_local_service);

        initView();
        Intent intent = new Intent(this, LocalServiceCount.class);
        bindService(intent, connection, Context.BIND_AUTO_CREATE);
        tv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_add.setText(myBinder.add(111,222)+"");
            }
        });

    }

    private void initView() {
        tv_add = (TextView) findViewById(R.id.tv_add);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}
